package com.bmit.ma.service;

import com.bmit.ma.mapper.ManagerMapper;
import com.bmit.ma.model.Manager;
import com.bmit.ma.model.ManagerKey;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagerServiceImpl implements IManagerService {
    @Autowired
    private ManagerMapper managerMapper; // 有红线正常

    @Override
    public List<Manager> selectAll() {
        return managerMapper.selectList();
    }

    @Override
    public Manager selectOne(String id, String name) {
        ManagerKey managerKey = new ManagerKey(Integer.parseInt(id), name);
        return managerMapper.selectByPrimaryKey(managerKey);
    }

    @Override
    public boolean insert(String id, String name, String password) {
        Manager manager = new Manager();
        manager.setId(Integer.parseInt(id));
        manager.setName(name);
        manager.setPassword(password);
        return managerMapper.insert(manager) > 0;
    }

    @Override
    public boolean delete(String id, String name) {
        ManagerKey managerKey = new ManagerKey(Integer.parseInt(id), name);
        return managerMapper.deleteByPrimaryKey(managerKey) > 0;
    }

    @Override
    public boolean update(String id, String name, String password) {
        Manager manager = new Manager();
        manager.setId(Integer.parseInt(id));
        manager.setName(name);
        manager.setPassword(password);
        return managerMapper.updateByPrimaryKey(manager) > 0;
    }
}
